
var express = require('express');
var router = express.Router();
var order = require("../models/order");
var getOpenid = require('../wechat/wechat.js');
const moment = require('moment');

//查看订单详情
router.get('/', async function(req, res, next) {
    let content = req.query;
    let code = content.code;
    let order_sheet = content.order_sheet;
    //
    // let string = await getOpenid(code);
    // let str = JSON.parse(string);
    // let openid = str.openid;


    order.find({order_sheet: order_sheet},{name:1,order_sheet:1,phone:1,message:1,preAddress:1,date:1,detailAddress:1,_id:0}, (err,docs) => {
        if(err){
            res.json({
                status:"1",
                msg:err.message
            })
        }else{
            let tmp = docs;
            let date = moment(tmp[0].date).format('YYYY-MM-DD HH:mm:ss');
            let tmp1 = [{
                date: date,
                phone: tmp[0].phone,
                message: tmp[0].message,
                detailAddress: tmp[0].detailAddress,
                name: tmp[0].name,
                order_sheet: tmp[0].order_sheet,
                preAddress: tmp[0].preAddress,
            }]
            res.json({
                status:"0",
                msg:"",
                result: tmp1
            })
        }
    })
});


module.exports = router;